//
//  ORSectionCollectionView.m
//  NewsHots
//
//  Created by rimi on 2016/12/2.
//  Copyright © 2016年 zhongshuilian. All rights reserved.
//

#import "ORSectionCollectionView.h"
#import "ORCollectionViewCell.h"

@interface ORSectionCollectionView () <UICollectionViewDataSource>

@end

@implementation ORSectionCollectionView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.collectionView];
        [self initializeAppearence];
    }
    return self;
}


-(void)initializeAppearence{
    // 网络请求
    NSString *appid = @"24762";
    NSString *sign = @"c0b7f94ce08f439d8d43e22b10fad680";
    NSDictionary *dic = @{@"showapi_appid":appid,@"showapi_sign":sign};
    [ORNetWorkRequestManager getMethod:@"http://route.showapi.com/109-34" withParames:dic Success:^(id respondObject) {
        NSLog(@"%@",respondObject);
        self.dataSource = respondObject[@"showapi_res_body"][@"channelList"];
        
            [self.collectionView reloadData];
        
    } Failure:^(NSError *error) {
        
    }];
    
}

#pragma mark - UICollectionViewDataSource

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ORCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"classinal" forIndexPath:indexPath];
    cell.nameLabel.text = _dataSource[indexPath.row][@"name"];
    
    cell.imageView.backgroundColor = MainColor;
    return cell;
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 20;
    
}

-(UICollectionView *)collectioView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake(80, 70);
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.minimumLineSpacing = 10.f;
        layout.minimumInteritemSpacing = (kBaseWidth - 80 * 4)/3;
        _collectionView = [[UICollectionView alloc]initWithFrame:AAdaptionRect(0, 0, self.frame.size.width, 180) collectionViewLayout:layout];
        _collectionView.dataSource = self;
        [_collectionView registerClass:[ORCollectionViewCell class] forCellWithReuseIdentifier:@"classinal"];
        _collectionView.backgroundColor = [UIColor redColor];
    }
    return  _collectionView;
}

@end
